package org.dawnframework.context.annotation;

import org.dawnframework.beans.factory.support.BeanDefinitionRegistry;
import org.dawnframework.beans.factory.support.DefaultableListBeanFactory;

/**
 * 注解处理的工具类
 */
public abstract class AnnotationConfigUtils {





    public static  void registerAnnotationConfigProcessors(BeanDefinitionRegistry registry){
      //这里是注册系统默认的配置类，注册的配置类放入bean工厂的map
        DefaultableListBeanFactory beanFactory =unwrapDefaultListableBeanFactory(registry);
        if(beanFactory != null){
            //这里可以设置默认工厂的一些参数，依赖解析，是否自动注入
        }
        //这里添加配置类

    }


    /**
     * 获取默认的工厂
     * @param registry
     * @return
     */
    private static DefaultableListBeanFactory unwrapDefaultListableBeanFactory(BeanDefinitionRegistry registry){
        DefaultableListBeanFactory beanFactory = null;

        if(registry instanceof DefaultableListBeanFactory){
            beanFactory = (DefaultableListBeanFactory)registry;
        }else if(registry instanceof GenericApplicationContext){
            beanFactory =((GenericApplicationContext) registry).getDefaultBeanFactory();
        }
        return beanFactory;
    }


}
